<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.min.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript"
	src="js/jquery-easyui-1.5.4.2/jquery.easyui.min.js"></script>
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/icon.css" />
<link rel="stylesheet" type="text/css"
	href="js/jquery-easyui-1.5.4.2/themes/black/easyui.css" />
<script type="text/javascript" src="js/common.js"></script>
<title>合同订单</title>
</head>
<body>

<style type="text/css">
.sep {
	margin-top: 15px;
}

.left {
	margin-top: 15px;
	margin-left: 50px;
}

#zj-order-details-form {
	color: black;
	font-size: 14px;
	font-family: '宋体';
}
</style>
	<script type="text/javascript">
		function go_to_cus_info(coCusId) {
			location = "index";
		}

		function editOrder(coId) {
			var row = $("#zj-order-dg").datagrid("getSelected");
			$("#zj-form-order-add").form('load', 'getOrderById?coId=' + coId);
			$("#zj-win-order-add").dialog({
				href2 : "editorder",
				title : "编辑合同订单"
			});
			$("#zj-form-cus").textbox({
				readonly : true
			});
			$("#zj-coStartTime").textbox({
				readonly : true
			})
				$("#zj-coEndTime").textbox({
				readonly : true
			})
				$("#zj-coSendTime").textbox({
				readonly : true
			})
			
			$("#zj-win-order-add").dialog("open");
		}

		function DetailsOrder(coId) {
			$("#zj-order-details-dg").dialog("open");
			$("#zj-order-details-form").form('load',
					'getOrderById?coId=' + coId);
			$("#zj-pro-details-dg").datagrid({
				url : 'getOrderDetailsById?coId=' + coId
			});
		}

		function deleteOrder(coId) {
			$.messager.confirm('提示', '确定要删除吗？', function(v) {
				if (v) {
					$.getJSON('deleteOrder', {
						coId : coId
					}, function(obj) {
						if (obj.success) {
							$('#zj-order-dg').datagrid('reload');
						} else {
							$.messager.alert('提示', '操作失败, 原因：' + obj.message);
						}
					});
				}
			});
		}

		$(function() {
			$.extend($.fn.validatebox.defaults.rules, {
				mobile : {
					validator : function(value, param) {
						return /^(?:13\d|15\d|18\d)-?\d{5}(\d{3}|\*{3})$/
								.test(value);
					},
					message : '手机号码不正确'
				}
			});

			$("#zj_btn_order_money_add").linkbutton({
				onClick : function() {
					$("#zj-co-od-zj-dialog").window("open");
				}
			});

			$("#zj-order-add-ok")
					.linkbutton(
							{
								onClick : function() {
									var row = $("#zj-order-dg").datagrid(
											"getSelected");
									$("#zj-form-order-add")
											.form(
													{
														url : $(
																'#zj-win-order-add')
																.dialog(
																		'options').href2,
														method : "post",
														onSubmit : function(
																params) {
															if (row != null) {
																params.coId = row.coId;
															}
															return $(this)
																	.form(
																			'validate');
														},
														success : function(v) {
															var obj = eval('('
																	+ v + ')');
															if (obj.success) {
																$(
																		'#zj-order-dg')
																		.datagrid(
																				'reload');
															} else {
																$.messager
																		.alert(
																				'提示',
																				'操作失败, 原因：'
																						+ obj.message);
															}
															$(
																	"#zj-win-order-add")
																	.window(
																			"close");
														}
													}).submit();
								}
							});

			$("#zj_btn_order_add").linkbutton({
				onClick : function() {
					$("#zj-win-order-add").dialog({
						href2 : "addNewOrder",
						title : "新建合同订单"
					});
					$("#zj-form-cus").textbox({
						readonly : false
					});
					$("#zj-form-order-add").form("clear");
					$("#zj-win-order-add").dialog("open");
				}
			});

			$("#zj_order_list_all").linkbutton({
				onClick : function() {
					$('#zj-order-dg').datagrid({
						pageNumber : 1,
						url : 'getAllOrder'
					});
					$("#zj-order-dg").datagrid("reload");
				}
			});

			$("#zj_order_query_by_some").linkbutton({
				onClick : function() {
					$("#zj-form-order-height-query").form("clear");
					$("#zj-order-height-query-dg").dialog("open");
				}
			});

			$("#zj-pro-details-dg").datagrid({
				fit : true,
				border : false,
				fitColumns : true,
				method : 'get',
				singleSelect : true,
				columns : [ [ {
					field : 'odProName',
					title : '名称',
					width : 2
				}, {
					field : 'odProType',
					title : '类别',
					width : 2
				}, {
					field : 'odRemarks',
					title : '产品单位',
					width : 1
				}, {
					field : 'odPrice',
					title : '单价',
					width : 1
				}, {
					field : 'odNumber',
					title : '数量',
					width : 1
				}, {
					field : 'name',
					title : '金额',
					width : 1,
					formatter : function(value, row, index) {
						return (row.odPrice * row.odNumber);
					}
				} ] ]
			});

			$("#zj-order-dg")
					.datagrid(
							{
								fit : true,
								border : false,
								toolbar : '#zj-order-tb',
								pageSize : 10,
								pageList : [3,5,8,9,10,15,20],
								fitColumns : true,
								url : 'getAllOrder',
								method : 'get',
								singleSelect : false,
								pagination : true,
								columns : [ [
										{
											field : 'cc',
											width : 1,
											checkbox : true
										},
										{
											field : 'coId',
											title : 'ID',
											width : 1
										},
										{
											field : 'coTheme',
											title : '主题',
											width : 3
										},
										{
											field : 'coCusIdvo',
											title : '客户id',
											width : 1,
											hidden : true
										},
										{
											field : 'coCusName',
											title : '对应客户',
											width : 2,
											formatter : function(value, row,
													index) {
												return value
														+ '<a class="zj-order-cus" onclick="go_to_cus_info('
														+ row.coCusId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
											}
										},
										{
											field : 'coAllMoney',
											title : '总金额',
											width : 3,
											formatter : function(value, row,
													index) {
												return "￥" + value;
											}
										},
										{
											field : 'coState',
											title : '状态',
											width : 2
										},
										{
											field : 'coOwner',
											title : '所有者',
											width : 2
										},
										{
											field : 'bb',
											width : 4,
											title : '操作',
											formatter : function(value, row,
													index) {
												var btn = '<a class="zj-order-edit" onclick="editOrder('
														+ row.coId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var btn2 = '<a class="zj-order-delete" onclick="deleteOrder('
														+ row.coId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												var btn3 = '<a class="zj-order-details" onclick="DetailsOrder('
														+ row.coId
														+ ')" href="javascript:void(0)" class="easyui-linkbutton"></a>';
												if (row.coState == '执行中') {
													return btn + btn2 + btn3;
												} else {
													return btn3;
												}
											}
										} ] ],
								onLoadSuccess : function(data) {
									$('.zj-order-edit').linkbutton({
										text : '编辑',
										plain : true,
										iconCls : 'icon-edit'
									});
									$('.zj-order-delete').linkbutton({
										text : '删除',
										plain : true,
										iconCls : 'icon-zj-delete'
									});
									$('.zj-order-details').linkbutton({
										text : '视图',
										plain : true,
										iconCls : 'icon-orderinfo'
									});
									$('.zj-order-cus').linkbutton({
										plain : true,
										iconCls : 'icon-customer'
									});
								},
								rowStyler : function(index, row) {
									return 'height:30px';
								}
							});
		});
	</script>
	<table id="zj-order-dg" class="easyui-datagrid">
	</table>

	<div id="zj-order-tb">
		<input class="easyui-searchbox" id="zj-order-theme"
			data-options="width:250,label:'主题：',labelWidth:55,searcher:function(value,name){
				$('#zj-order-dg').datagrid({pageNumber:1, url: 'getOrderByTheme'});
				//重新加载数据
				$('#zj-order-dg').datagrid('load', {coTheme: value});
			}">
		<!-- 	<a id="zj_btn_order_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">单表添加</a>  -->
		<a id="zj_btn_order_money_add" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:true">添加</a> <a
			id="zj_order_list_all" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-reload',plain:true">刷新</a> <a
			id="zj_order_query_by_some" href="javascript:void(0)"
			class="easyui-linkbutton"
			data-options="iconCls:'icon-search',plain:true">高级查询</a>
	</div>

	<div id="zj-co-od-zj-dialog" class="easyui-dialog"
		style="width: 1200px; height: 550px; padding: 10px;"
		data-options="href:'toCood',title:'添加订单和明细',iconCls:'icon-add',resizable:true,modal:true,closed:true"></div>

	<div id="zj-win-order-add" class="easyui-dialog"
		style="width: 475px; height: 600px; padding: 10px;"
		data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding: 10px;">
				<form id="zj-form-order-add" name="orderForm" method="post">
					<div class="sep">
						<input class="easyui-textbox"
							data-options="required:true,labelAlign:'right',label:'主题',
					width:220, labelWidth:60"
							name="coTheme">
					</div>
					<input name="coCusId" type="hidden" class="easyui-textbox"
						id="zj-order-custid">
					<div class="sep">
						<input id="zj-form-cus" name="coCusName" class="easyui-textbox"
							data-options="buttonText:'选择客户',label:' ',labelWidth:'60', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-form-cus').textbox('setValue', row.custName);
							$('#zj-form-cus').textbox('setText', row.custName);
							$('#zj-order-custid').textbox('setValue',row.custId);
						});
					}">
					</div>

					<div class="sep">
						<select class="easyui-combobox"
							data-options="panelHeight:'auto',labelAlign:'right',required:true,label:'付款方式',
					width:280, labelWidth:62"
							name="coPayWay">
							<option disabled selected value=''></option>
							<option value="支票">支票</option>
							<option value="现金">现金</option>
							<option value="邮政汇款">邮政汇款</option>
							<option value="网上银行">网上银行</option>
						</select>
					</div>

					<div class="sep">
						<select name="coType" class="easyui-combobox"
							data-options="panelHeight:'auto',labelAlign:'right',required:false,label:'分类',
					width:250, labelWidth:60"
							name="coType">
							<option disabled selected value=''></option>
							<option value="产品销售">产品销售</option>
							<option value="服务">服务</option>
							<option value="业务合作">业务合作</option>
							<option value="代理分销">代理分销</option>
							<option value="其他">其他</option>
						</select>
					</div>

					<div class="sep">
						<input class="easyui-numberbox" name="coAllMoney"
							data-options="min:0,precision:2,labelAlign:'right',required:true,label:'总金额',
					width:200, labelWidth:60">
					</div>

					<div class="sep">
						<input id="zj-coStartTime" class="easyui-datebox"
							data-options="required:true,labelAlign:'right',label:'签约日期',
					width:300, labelWidth:62"
							name="coStartTime">
					</div>
					<div class="sep">
						<input id="zj-coEndTime" class="easyui-datebox"
							data-options="required:true,labelAlign:'right',label:'结束日期',
					width:280, labelWidth:62"
							name="coEndTime">
					</div>
					<div class="sep">
						<input id="zj-coSendTime" class="easyui-datebox"
							data-options="required:true,labelAlign:'right',label:'发货时间',
					width:280, labelWidth:62"
							name="coSendTime">
					</div>

					<div class="sep">
						<input class="easyui-textbox"
							data-options="multiline:true,required:false,labelAlign:'right',label:'备注',
					width:320,height:35,labelWidth:60"
							name="coRemarks">
					</div>

					<div class="sep">
						<input class="easyui-textbox"
							data-options="multiline:true,labelAlign:'right',required:false,label:'正文',
					width:340,height:55,labelWidth:60"
							name="coText">
					</div>

					<div class="sep" style="margin-left: 30px;">
						状态<input style="margin-left: 20px;" value="执行中" name="coState"
							checked="checked" type="radio">执行中<input value="结束"
							name="coState" type="radio">结束
					</div>

					<div class="sep">
						<input id="zj-form-owner" name="coOwner" class="easyui-textbox"
							data-options="buttonText:'所有者', label:' ', labelWidth:'60', width: 300, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-form-owner').textbox('setValue', row.custName);
						});
					}">
					</div>

					<div class="sep">
						<input class="easyui-textbox"
							data-options="required:false,labelAlign:'right',label:'收货人',
					width:200, labelWidth:60"
							name="coGetMan">
					</div>
					<div class="sep">
						<input class="easyui-textbox"
							data-options="required:false,labelAlign:'right',validType:'mobile',label:'电话',
					width:300, labelWidth:60"
							name="coManPhone">
					</div>
					<div class="sep">
						<input class="easyui-textbox"
							data-options="required:false,labelAlign:'right',label:'地址',
					width:350, labelWidth:60"
							name="coManAddress">
					</div>
					<div class="sep">
						<input id="code" class="easyui-textbox"
							data-options="required:false,labelAlign:'right',validType:'email',label:'邮编',
					width:250, labelWidth:60"
							name="code">
					</div>
				</form>
			</div>

			<div id="zj-order-details-dg" class="easyui-dialog" title="订单详情"
				style="width: 900px; height: 650px;"
				data-options="iconCls:'icon-save',resizable:true,modal:true,closed:true">
				<div id="cc" class="easyui-layout"
					style="width: 900px; height: 400px;">
					<div data-options="region:'center',border:false"
						style="padding: 5px; background: #eee;">
						<form id="zj-order-details-form" method="post">
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'主题',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coTheme"> <input class="easyui-textbox"
									data-options="label:'客户',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coCusNamevo">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'合同类型',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coType"> <input class="easyui-textbox"
									data-options="label:'总金额',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coAllMoney">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'付款方式',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coPayWay"> <input class="easyui-textbox"
									data-options="label:'结款方式',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coJieWay">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'签约时间',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coStartTime"> <input class="easyui-textbox"
									data-options="label:'结束时间',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coEndTime">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'所有者',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coOwner"> <input class="easyui-textbox"
									data-options="label:'状态',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coState">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'最晚发货时间',width:330, labelWidth:92,readonly:true,labelAlign:'right'"
									name="coSendTime"> <input class="easyui-textbox"
									data-options="label:'地址',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coManAddress">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'收货人',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coGetMan"> <input class="easyui-textbox"
									data-options="label:'电话',width:330,labelWidth:90,readonly:true,labelAlign:'right'"
									name="coManPhone">
							</div>
							<div class="left">
								<input class="easyui-textbox"
									data-options="label:'备注',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coRemarks"> <input class="easyui-textbox"
									data-options="label:'正文',width:330, labelWidth:90,readonly:true,labelAlign:'right'"
									name="coText">
							</div>
						</form>
					</div>
				</div>

				<div id="bb" class="easyui-layout"
					style="width: 900px; height: 300px;">
					<div data-options="region:'center',border:false"
						style="padding: 5px; background: #eee;">
						<table id="zj-pro-details-dg"></table>
					</div>
				</div>


			</div>
			<div data-options="region:'south',border:false"
				style="text-align: right; padding: 5px 0 0;">
				<a id="zj-order-add-ok" class="easyui-linkbutton"
					data-options="iconCls:'icon-ok',plain:true">保存</a><a
					class="easyui-linkbutton"
					data-options="iconCls:'icon-cancel',plain:true"
					href="javascript:void(0)"
					onclick="javascript:$('#zj-win-order-add').window('close');">关闭</a>
			</div>
		</div>
	</div>

	<div id="zj-order-height-query-dg" class="easyui-dialog" title="订单高级查询"
		style="width: 550px; height: 670px;"
		data-options="iconCls:'icon-save',closed:true,resizable:true,modal:true,buttons:[{
				text:'查询',
				iconCls:'icon-ok',
				handler:function(){
				dg = $('#zj-order-dg').datagrid('getPager').data('pagination').options;
				$('#zj-form-order-height-query').form({
					url:'getOrderSome',
					method:'post',
					onSubmit:function(param){
						param.page = dg.pageNumber;
						param.rows = dg.pageSize;
					},
					success:function(v){
						var json = JSON.parse(v);
						$('#zj-order-dg').datagrid('loadData',json);
						$('#zj-order-height-query-dg').dialog('close');
					}		
				}).submit();
				}
			},{
				text:'关闭',
				iconCls:'icon-cancel',
				handler:function(){
					$('#zj-order-height-query-dg').dialog('close');
				}
			}]">

		<form id="zj-form-order-height-query" method="post">
			<div class="sep">
				<input class="easyui-textbox"
					data-options="labelAlign:'right',label:'主题',
					width:350, labelWidth:90"
					name="coTheme">
			</div>
			<div class="sep">
				<input id="zj-form-height-query-cus" name="coCusName"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'选择客户',label:' ',labelWidth:'90', width: 410, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-form-height-query-cus').textbox('setValue', row.custName);
							$('#zj-form-height-query-cus').textbox('setText', row.custName);
						});
					}">
			</div>

			<div class="sep">
				<select class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',label:'付款方式',
					width:410, labelWidth:90"
					name="coPayWay">
					<option disabled selected value=''></option>
					<option value="支票">支票</option>
					<option value="现金">现金</option>
					<option value="邮政汇款">邮政汇款</option>
					<option value="网上银行">网上银行</option>
				</select>
			</div>

			<div class="sep">
				<select name="coType" class="easyui-combobox"
					data-options="editable:false,panelHeight:'auto',labelAlign:'right',label:'分类',
					width:410, labelWidth:90"
					name="coType">
					<option disabled selected value=''></option>
					<option value="产品销售">产品销售</option>
					<option value="服务">服务</option>
					<option value="业务合作">业务合作</option>
					<option value="代理分销">代理分销</option>
					<option value="其他">其他</option>
				</select>
			</div>

			<div class="sep">
				<input class="easyui-numberbox" name="coAllMoney"
					data-options="min:0,precision:2,labelAlign:'right',label:'总金额',
					width:300, labelWidth:90">
			</div>

			<!-- 	<div class="sep">
				<input class="easyui-datebox"
					data-options="labelAlign:'right',label:'签约日期',
					width:410, labelWidth:60"
					name="coStartTime">
			</div>
			<div class="sep">
				<input class="easyui-datebox"
					data-options="labelAlign:'right',label:'结束日期',
					width:410, labelWidth:60"
					name="coEndTime">
			</div>
			<div class="sep">
				<input class="easyui-datebox"
					data-options="labelAlign:'right',label:'发货时间',
					width:410, labelWidth:80"
					name="coSendTime">
			</div> -->

			<div class="sep">
				<input class="easyui-textbox"
					data-options="multiline:true,required:false,labelAlign:'right',label:'备注',
					width:410,height:35,labelWidth:90"
					name="coRemarks">
			</div>

			<div class="sep">
				<input class="easyui-textbox"
					data-options="multiline:true,labelAlign:'right',required:false,label:'正文',
					width:410,height:55,labelWidth:90"
					name="coText">
			</div>

			<div class="sep" style="margin-left: 30px;">
				状态<input style="margin-left: 20px;" value="执行中" name="coState"
					checked="checked" type="radio">执行中<input value="结束"
					name="coState" type="radio">结束
			</div>

			<div class="sep">
				<input id="zj-form-height-query-owner" name="coOwner"
					class="easyui-textbox"
					data-options="editable:false,buttonText:'所有者', label:' ', labelWidth:'90', width: 410, 
					onClickButton:function(){
						getCustomer(function(row){
							$('#zj-form-height-query-owner').textbox('setValue', row.custName);
						});
					}">
			</div>

			<div class="sep">
				<input class="easyui-textbox"
					data-options="required:false,labelAlign:'right',label:'收货人',
					width:410, labelWidth:90"
					name="coGetMan">
			</div>
			<div class="sep">
				<input class="easyui-textbox"
					data-options="required:false,labelAlign:'right',validType:'mobile',label:'电话',
					width:410, labelWidth:90"
					name="coManPhone">
			</div>
			<div class="sep">
				<input class="easyui-textbox"
					data-options="required:false,labelAlign:'right',label:'地址',
					width:410, labelWidth:90"
					name="coManAddress">
			</div>
			<div class="sep">
				<input id="code" class="easyui-textbox"
					data-options="required:false,labelAlign:'right',validType:'email',label:'邮编',
					width:410, labelWidth:90"
					name="code">
			</div>
		</form>
	</div>
</body>
</html>